//
//  AnnouncementmaiViewController.m
//  PlayerWorld
//
//  Created by 1 on 16/5/1.
//  Copyright © 2016年 刘成. All rights reserved.
//
#define SCREEN_WIDTH   ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT  ([[UIScreen mainScreen] bounds].size.height)

#import "AnnouncementmaiViewController.h"
#import "TableViewController.h"
#import "TableController.h"

@interface AnnouncementmaiViewController (){
    UISegmentedControl *segment;
    UIScrollView *_scrollView;
    TableViewController *TableView;
    TableController *Table;
}

@end

@implementation AnnouncementmaiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:nil];
    self.view.backgroundColor = [UIColor yellowColor];
    self.tabBarController.tabBar.hidden = YES;
    self.title = @"公告";
    
    if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    [self setSegmentedControl];
    [self build];

}

-(void)build
{
    
    _scrollView = [[UIScrollView alloc] init];
    _scrollView.backgroundColor = [UIColor redColor];
    _scrollView.frame = CGRectMake(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
    _scrollView.contentSize = CGSizeMake(SCREEN_WIDTH*2,SCREEN_HEIGHT-64);
    _scrollView.pagingEnabled = YES;
    _scrollView.scrollEnabled = NO;
    [self.view addSubview:_scrollView];
    
    
    TableView = [[TableViewController alloc]init];
    TableView.view.frame = CGRectMake(0,0,SCREEN_WIDTH,SCREEN_HEIGHT-64);
    
    [self addChildViewController:TableView];
    [_scrollView addSubview:TableView.view];
    
    
    
    Table = [[TableController alloc]init];
    CGRect aframe = CGRectMake(SCREEN_WIDTH,0,SCREEN_WIDTH,SCREEN_HEIGHT-64);
    
    Table.view.frame =aframe;
    
    [self addChildViewController:Table];
    [_scrollView addSubview:Table.view];
}

-(void)setSegmentedControl{
    
    if (!segment) {
        
        segment = [[UISegmentedControl alloc]initWithItems:nil];
        segment.frame=CGRectMake(0, 7, 180, 30);
//        segment.tintColor = [UIColor whiteColor];
//        segment.backgroundColor = [UIColor blackColor];
        [segment insertSegmentWithTitle:
         @"公告" atIndex: 0 animated: NO ];
        [segment insertSegmentWithTitle:
         @"站内信" atIndex: 1 animated: NO ];
        
        //segment.segmentedControlStyle= UISegmentedControlStyleBar;
        
        segment.selectedSegmentIndex = 0;//设置默认选择项索引
        //设置跳转的方法
        [segment addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
        self.navigationItem.titleView = segment;
    }
    
}
-(void)change:(UISegmentedControl *)Seg{
    switch (Seg.selectedSegmentIndex) {
            
        case 0:{
            [_scrollView setContentOffset:CGPointMake(_scrollView.bounds.size.width * Seg.selectedSegmentIndex, 0) animated:YES];
            break;
        }
        case 1:{
            [_scrollView setContentOffset:CGPointMake(_scrollView.bounds.size.width * Seg.selectedSegmentIndex, 0) animated:YES];
            break;
        }
        default:
            break;
    }
}


@end
